package com.spbdx.web.controller.pc.system;


import com.spbdx.common.annotation.Log;
import com.spbdx.common.core.controller.BaseController;
import com.spbdx.common.core.domain.AjaxResult;
import com.spbdx.common.core.page.TableDataInfo;
import com.spbdx.common.enums.BusinessType;
import com.spbdx.common.utils.poi.ExcelUtil;
import com.spbdx.system.domain.SysPic;
import com.spbdx.system.service.ISysPicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 图片Controller
 *
 * @author cms
 * @date 2024-02-27
 */
@RestController
@RequestMapping("/system/pic")
public class SysPicController extends BaseController
{
    @Autowired
    private ISysPicService sysPicService;

    /**
     * 查询图片列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysPic sysPic)
    {
        startPage();
        List<SysPic> list = sysPicService.selectSysPicList(sysPic);
        return getDataTable(list);
    }

    /**
     * 导出图片列表
     */
    @Log(title = "图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPic sysPic)
    {
        List<SysPic> list = sysPicService.selectSysPicList(sysPic);
        ExcelUtil<SysPic> util = new ExcelUtil<SysPic>(SysPic.class);
        util.exportExcel(response, list, "图片数据");
    }

    /**
     * 获取图片详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysPicService.selectSysPicById(id));
    }

    /**
     * 新增图片
     */
    @Log(title = "图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPic sysPic)
    {
        return toAjax(sysPicService.insertSysPic(sysPic));
    }

    /**
     * 修改图片
     */
    @Log(title = "图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPic sysPic)
    {
        return toAjax(sysPicService.updateSysPic(sysPic));
    }

    /**
     * 删除图片
     */
    @Log(title = "图片", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysPicService.deleteSysPicByIds(ids));
    }
}
